package com.zzw.grpc;

import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;

import java.io.IOException;

/**
 * @author Administrator
 */
public class DefaultGrpcServer extends RecEverGrpc.RecEverImplBase {

    public DefaultGrpcServer(GrpcServerProperties grpcServerProperties) {
        try {
            ServerBuilder.forPort(grpcServerProperties.getPost())
                    .addService(this)
                    .build()
                    .start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void recEve(RecEverything.RecEveRequest request, StreamObserver<RecEverything.RecEveResponse> responseObserver) {
        String responseMessage = "Received: " + request.getRequest();
        RecEverything.RecEveResponse response = RecEverything.RecEveResponse.newBuilder().setData(responseMessage).build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
